<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>方案反馈页面</title>
    <script src="../../res/layui/layui.js" charset="utf-8" media="all"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<style>
    #btn{
        margin-top: 10px;
        margin-left: 124px;
    }
    #div{
        height:10px;
    }
</style>
<body>
    <form class="layui-form" action="" id="from">
        <input id="schemeId" name="schemeId" hidden></input>

        <div class="layui-form-item">
            <label class="layui-form-label">实施情况</label>
            <div class="layui-input-block">
                <textarea id="resultExp" name="resultExp" required lay-verify="required" style="margin: 0px; width: 350px; height: 143px;" placeholder="请填写具体实施情况" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">实施效果</label>
            <div class="layui-input-block">
                <textarea id="resultEffect" name="resultEffect" required lay-verify="required" style="margin: 0px; width: 350px; height: 143px;" placeholder="请填写实施效果" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">实施附件</label>
            <div class="layui-input-block">
                <input type="file" name="File">
            </div>
        </div>

        <div style="width: 216px; margin: 0;">
            <button id="btn" type="button" class="layui-btn layui-btn-fluid" lay-submit lay-filter="formDemo">提交</button>
        </div>
        <div id="div"></div>
    </form>
    <script>
        $(function () {
            findById();
        })
        var form=null;
        layui.use(['form','laydate'], function(){
            form = layui.form;

            /*不为空判定*/
            form.verify({
                resultExp:function(value){
                    if(value==""){
                        return '必须要填写实施情况';
                    };
                },
                resultEffect:function(value){
                    if(value==""){
                        return '必须要写实施附件';
                    };
                }
            });

            form.on('submit(formDemo)', function(data){

                var formData = new FormData(document.getElementById("from"));
                var url="../../AtsSchemeAction/addorupdate?feedback="+1
                $.ajax({
                    url:url,
                    type:"post",
                    data:formData,
                    async:false,
                    processData:false,
                    contentType:false,
                    dataType:"json",
                    success:function(obj){
                        if(obj.num==1){
                            layer.msg("操作成功",{
                                icon:1,
                                time:1000 //1秒关闭(如果不配置默认三秒)
                            },function(){
                                //关闭当前层
                                //当你在iframe页面关闭自身时
                                var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                //刷新父页面
                                parent.location.reload();
                            });
                        }else{
                            alert("操作失败")
                        }
                    },
                    error:function(e){
                    }
                });
                return false;
            })

        })


        /*得到上一个页面传过来的值*/
        function getQueryStringOne(key) {
            var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null)
                return decodeURI(r[2]);
            return null;
        }
        /*修改页面赋值*/
        function findById(){
            var id=getQueryStringOne("id");
            $("#schemeId").val(id);
        }
    </script>
</body>
</html>